**********************************************************************************************
//*SET USER*//
*Users Identification Code
*User 1
*User 2


//Set user below:
global user 2

//Enter the filepath of where the Master Folder is located//
*********************************************************
//User 1
if $user == 1 {
	global FH ""
}
**********************************************************
//User 2
if $user == 2 {

	global FH ""
}
************************************************************
*************************PHILIPPINES************************
************************************************************

//GENERATING SCORES
ssc install winsor
do "$FH/do/Scores/PHL_HOC_Scores.do"
///OVERALL PICKUP RATE
sum es_total_pickup

scalar a1 = round((r(mean)/r(max))*100,  1)


///PICKUP RATE
sum es_m1_pickup

scalar c11 = round((r(mean)/r(max))*100,  1)

sum es_m2_pickup

scalar c21 = round((r(mean)/r(max))*100,  1)

sum es_m3_pickup

scalar c31 = round((r(mean)/r(max))*100,  1)

sum es_m4_pickup

scalar c41 = round((r(mean)/r(max))*100,  1)

///MODULE WISE PICKUP RATE REGARDLESS OF PICKUP 
sum es_m1_listenratio

scalar c12 = round(r(mean), 1)


sum es_m2_listenratio

scalar c22 = round(r(mean), 1)

sum es_m3_listenratio

scalar c32 = round(r(mean), 1)

sum es_m4_listenratio

scalar c42 = round(r(mean), 1)

sum es_total_listenratio

scalar a2 = round(r(mean), 1)


///MODULE WISE LISTENERSHIP CONDITIONAL ON PICKUP 

local M1 "w1 w2 w3 w4 w5 w6 w7"
foreach v of local M1 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}
gen cond_es_m1_listenratio = (cond_es_w1_listenratio + cond_es_w2_listenratio + cond_es_w3_listenratio + cond_es_w4_listenratio + cond_es_w5_listenratio + cond_es_w6_listenratio + cond_es_w7_listenratio)/7

local M2 "w8 w9 w10 w11 w12"
foreach v of local M2 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}

gen cond_es_m2_listenratio = (cond_es_w8_listenratio + cond_es_w9_listenratio + cond_es_w10_listenratio + cond_es_w11_listenratio + cond_es_w12_listenratio)/5

local M3 "w13 w14 w15 w16 w17 w18"
foreach v of local M3 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}

gen cond_es_m3_listenratio = (cond_es_w13_listenratio + cond_es_w14_listenratio + cond_es_w15_listenratio + cond_es_w16_listenratio + cond_es_w17_listenratio + cond_es_w18_listenratio)/6

local M4 "w19 w20 w21"
foreach v of local M4 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}

gen cond_es_m4_listenratio = (cond_es_w19_listenratio + cond_es_w20_listenratio + cond_es_w21_listenratio)/3

//gen cond_es_total_listenratio = (cond_es_m1_listenratio + cond_es_m2_listenratio + cond_es_m3_listenratio + cond_es_m4_listenratio)/4 

gen cond_es_total_listenratio = (cond_es_w1_listenratio + cond_es_w2_listenratio + cond_es_w3_listenratio + cond_es_w4_listenratio + cond_es_w5_listenratio + cond_es_w6_listenratio + cond_es_w7_listenratio + cond_es_w8_listenratio + cond_es_w9_listenratio + cond_es_w10_listenratio + cond_es_w11_listenratio + cond_es_w12_listenratio + cond_es_w13_listenratio + cond_es_w14_listenratio + cond_es_w15_listenratio + cond_es_w16_listenratio + cond_es_w17_listenratio + cond_es_w18_listenratio + cond_es_w19_listenratio + cond_es_w20_listenratio + cond_es_w21_listenratio)/21


sum cond_es_m1_listenratio 

scalar c13 = round(r(mean), 1)

sum cond_es_m2_listenratio 

scalar c23 = round(r(mean), 1)

sum cond_es_m3_listenratio 

scalar c33 = round(r(mean), 1)

sum cond_es_m4_listenratio 

scalar c43 = round(r(mean), 1)

sum cond_es_total_listenratio 

scalar a3 = round(r(mean), 1)

************************************************************
*************************INDIA******************************
************************************************************
//*SET DIRECTORY & LOAD DATA & GENERATE SCORES*//
clear
do "$FH/do/Scores/IND_HOC_Scores.do"

foreach var of varlist es_total_pickup es_m1_pickup es_m2_pickup es_m3_pickup es_m4_pickup  {
	replace `var' = . if `var' == -1
}

foreach var of varlist es_m1_listenratio es_m2_listenratio es_m3_listenratio es_m4_listenratio es_total_listenratio {
	replace `var' = . if `var' < 0
}


///OVERALL PICKUP RATE
sum es_total_pickup

scalar ind_a1 = round((r(mean)/r(max))*100,  1)


///PICKUP RATE
sum es_m1_pickup

scalar ind_c11 = round((r(mean)/r(max))*100,  1)

sum es_m2_pickup

scalar ind_c21 = round((r(mean)/r(max))*100,  1)

sum es_m3_pickup

scalar ind_c31 = round((r(mean)/r(max))*100,  1)

sum es_m4_pickup

scalar ind_c41 = round((r(mean)/r(max))*100,  1)

///MODULE WISE PICKUP RATE REGARDLESS OF PICKUP 
sum es_m1_listenratio

scalar ind_c12 = round(r(mean), 1)


sum es_m2_listenratio

scalar ind_c22 = round(r(mean), 1)

sum es_m3_listenratio

scalar ind_c32 = round(r(mean), 1)

sum es_m4_listenratio

scalar ind_c42 = round(r(mean), 1)

sum es_total_listenratio

scalar ind_a2 = round(r(mean), 1)


///MODULE WISE LISTENERSHIP CONDITIONAL ON ALL CALLS BEING PICKED UP
local M1 "w1 w2 w3 w4 w5 w6 w7"
foreach v of local M1 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}
gen cond_es_m1_listenratio = (cond_es_w1_listenratio + cond_es_w2_listenratio + cond_es_w3_listenratio + cond_es_w4_listenratio + cond_es_w5_listenratio + cond_es_w6_listenratio + cond_es_w7_listenratio)/7

local M2 "w8 w9 w10 w11 w12"
foreach v of local M2 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}

gen cond_es_m2_listenratio = (cond_es_w8_listenratio + cond_es_w9_listenratio + cond_es_w10_listenratio + cond_es_w11_listenratio + cond_es_w12_listenratio)/5

local M3 "w13 w14 w15 w16 w17 w18"
foreach v of local M3 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}

gen cond_es_m3_listenratio = (cond_es_w13_listenratio + cond_es_w14_listenratio + cond_es_w15_listenratio + cond_es_w16_listenratio + cond_es_w17_listenratio + cond_es_w18_listenratio)/6

local M4 "w19 w20 w21 w22"
foreach v of local M4 {
	gen cond_es_`v'_listenratio = es_`v'_listenratio if es_`v'_pickup == 1 
}

gen cond_es_m4_listenratio = (cond_es_w19_listenratio + cond_es_w20_listenratio + cond_es_w21_listenratio + cond_es_w22_listenratio)/4

//gen cond_es_total_listenratio = (cond_es_m1_listenratio + cond_es_m2_listenratio + cond_es_m3_listenratio + cond_es_m4_listenratio)/4 

gen cond_es_total_listenratio = (cond_es_w1_listenratio + cond_es_w2_listenratio + cond_es_w3_listenratio + cond_es_w4_listenratio + cond_es_w5_listenratio + cond_es_w6_listenratio + cond_es_w7_listenratio + cond_es_w8_listenratio + cond_es_w9_listenratio + cond_es_w10_listenratio + cond_es_w11_listenratio + cond_es_w12_listenratio + cond_es_w13_listenratio + cond_es_w14_listenratio + cond_es_w15_listenratio + cond_es_w16_listenratio + cond_es_w17_listenratio + cond_es_w18_listenratio + cond_es_w19_listenratio + cond_es_w20_listenratio + cond_es_w21_listenratio + cond_es_w22_listenratio)/22


sum cond_es_m1_listenratio 

scalar ind_c13 = round(r(mean), 1)

sum cond_es_m2_listenratio 

scalar ind_c23 = round(r(mean), 1)

sum cond_es_m3_listenratio 

scalar ind_c33 = round(r(mean), 1)

sum cond_es_m4_listenratio 

scalar ind_c43 = round(r(mean), 1)

sum cond_es_total_listenratio 

scalar ind_a3 = round(r(mean), 1)



*******************************
********TABLE 2A***************
*******************************

file open table2a using "$FH/tables/Table 2A.tex", write replace text
set more off
file write table2a "\documentclass[12pt]{article}" _n
file write table2a "\usepackage{amsmath}" _n
file write table2a "\usepackage{latexsym}" _n
file write table2a "\usepackage{amsfonts}" _n
file write table2a "\usepackage{xcolor}" _n
file write table2a "\usepackage{booktabs}" _n
file write table2a "\usepackage{tabularx}" _n
file write table2a "\usepackage{adjustbox}" _n
file write table2a "\begin{document}" _n

file write table2a "\begin{table}[htbp] \\" _n
file write table2a "\centering " _n
file write table2a "\begin{adjustbox}{width=1.1\textwidth} " _n
file write table2a "\begin{tabular}{p{9.75em}rrr} \\" _n
file write table2a "\multicolumn{4}{c}{\textbf{TABLE 2A: Pickup \& Listening Rates-Philippines}} \\" _n
file write table2a "\midrule" _n
file write table2a "\midrule" _n
file write table2a "\multicolumn{1}{r}{} & \multicolumn{1}{c}{{\textbf{Pick-up Rate (\%)}}} & \multicolumn{1}{c}{\textbf{Listening Rate}} & \multicolumn{1}{c}{\textbf{Listening Rate}} \\" _n
file write table2a "\multicolumn{1}{r}{} &       & \multicolumn{1}{c}{\textbf{Regardless of}} & \multicolumn{1}{c}{\textbf{Conditional on}} \\" _n
file write table2a "\multicolumn{1}{r}{} &       & \multicolumn{1}{c}{\textbf{Pick-up (\%)}} & \multicolumn{1}{c}{\textbf{Pick-up (\%)}} \\" _n
    
file write table2a "\cmidrule{2-4}    \multicolumn{1}{l}{\textbf{Module}} & \multicolumn{1}{c}{\textbf{(1)}} & \multicolumn{1}{c}{\textbf{(2)}} & \multicolumn{1}{c}{\textbf{(3)}} \\" _n
file write table2a "\midrule \\" _n
file write table2a "\multicolumn{1}{l}{Cash Separation} & \multicolumn{1}{c}{" (c11) "\%} & \multicolumn{1}{c}{" (c12) "\%} & \multicolumn{1}{c}{" (c13) "\%} \\" _n
file write table2a "\multicolumn{1}{l}{Customer Credit} & \multicolumn{1}{c}{" (c21) "\%} & \multicolumn{1}{c}{" (c22) "\%} & \multicolumn{1}{c}{" (c23) "\%} \\" _n
file write table2a "\multicolumn{1}{l}{Inventory Management} & \multicolumn{1}{c}{" (c31) "\%} & \multicolumn{1}{c}{" (c32) "\%} & \multicolumn{1}{c}{" (c33) "\%} \\" _n
file write table2a "\multicolumn{1}{l}{Supplier Management} & \multicolumn{1}{c}{" (c41) "\%} & \multicolumn{1}{c}{" (c42) "\%} & \multicolumn{1}{c}{" (c43) "\%} \\" _n
file write table2a "\multicolumn{1}{l}{\textbf{Overall}} & \multicolumn{1}{c}{\textbf{" (a1) "\%}} & \multicolumn{1}{c}{\textbf{" (a2) "\%}} & \multicolumn{1}{c}{\textbf{" (a3) "\%}} \\" _n
file write table2a "\midrule" _n
file write table2a "\midrule" _n
file write table2a "\multicolumn{4}{p{42em}}{\textbf{Notes:} This table presents the pick up rates and listening rates for each section of financial heuristics training curriculum. Pick up rate = number of pickups / total number of calls. Listing rate regardless of pick up = listenership / total duration. Listening rate conditional on pick up = listenership / total duration if call picked up.} \\"
file write table2a "\bottomrule \\" _n
file write table2a "\end{tabular}% \\" _n
file write table2a "\label{tab:addlabel}% \\" _n
file write table2a "\end{adjustbox} \\" _n
file write table2a "\end{table}% \\" _n
file write table2a "\end{document}"


file close table2a
set more on

*******************************
********TABLE 2B***************
*******************************


file open table2b using "$FH/tables/Table 2B.tex", write replace text
set more off
file write table2b "\documentclass[12pt]{article}" _n
file write table2b "\usepackage{amsmath}" _n
file write table2b "\usepackage{latexsym}" _n
file write table2b "\usepackage{amsfonts}" _n
file write table2b "\usepackage{xcolor}" _n
file write table2b "\usepackage{booktabs}" _n
file write table2b "\usepackage{tabularx}" _n
file write table2b "\usepackage{adjustbox}" _n
file write table2b "\begin{document}" _n

file write table2b "\begin{table}[htbp] \\" _n
file write table2b "\centering " _n
file write table2b "\begin{adjustbox}{width=1.1\textwidth} " _n
file write table2b "\begin{tabular}{p{9.75em}rrr} \\" _n
file write table2b "\multicolumn{4}{c}{\textbf{TABLE 2B: Pickup \& Listening Rates-India}} \\" _n
file write table2b "\midrule" _n
file write table2b "\midrule" _n
file write table2b "\multicolumn{1}{r}{} & \multicolumn{1}{c}{{\textbf{Pick-up Rate (\%)}}} & \multicolumn{1}{c}{\textbf{Listening Rate}} & \multicolumn{1}{c}{\textbf{Listening Rate}} \\" _n
file write table2b "\multicolumn{1}{r}{} &       & \multicolumn{1}{c}{\textbf{Regardless of}} & \multicolumn{1}{c}{\textbf{Conditional on}} \\" _n
file write table2b "\multicolumn{1}{r}{} &       & \multicolumn{1}{c}{\textbf{Pick-up (\%)}} & \multicolumn{1}{c}{\textbf{Pick-up (\%)}} \\" _n
    
file write table2b "\cmidrule{2-4}    \multicolumn{1}{l}{\textbf{Module}} & \multicolumn{1}{c}{\textbf{(1)}} & \multicolumn{1}{c}{\textbf{(2)}} & \multicolumn{1}{c}{\textbf{(3)}} \\" _n
file write table2b "\midrule \\" _n
file write table2b "\multicolumn{1}{l}{Cash Separation} & \multicolumn{1}{c}{" (ind_c11) "\%} & \multicolumn{1}{c}{" (ind_c12) "\%} & \multicolumn{1}{c}{" (ind_c13) "\%} \\" _n
file write table2b "\multicolumn{1}{l}{Customer Credit} & \multicolumn{1}{c}{" (ind_c21) "\%} & \multicolumn{1}{c}{" (ind_c22) "\%} & \multicolumn{1}{c}{" (ind_c23) "\%} \\" _n
file write table2b "\multicolumn{1}{l}{Inventory Management} & \multicolumn{1}{c}{" (ind_c31) "\%} & \multicolumn{1}{c}{" (ind_c32) "\%} & \multicolumn{1}{c}{" (ind_c33) "\%} \\" _n
file write table2b "\multicolumn{1}{l}{Supplier Management} & \multicolumn{1}{c}{" (ind_c41) "\%} & \multicolumn{1}{c}{" (ind_c42) "\%} & \multicolumn{1}{c}{" (ind_c43) "\%} \\" _n
file write table2b "\multicolumn{1}{l}{\textbf{Overall}} & \multicolumn{1}{c}{\textbf{" (ind_a1) "\%}} & \multicolumn{1}{c}{\textbf{" (ind_a2) "\%}} & \multicolumn{1}{c}{\textbf{" (ind_a3) "\%}} \\" _n
file write table2b "\midrule" _n
file write table2b "\midrule" _n
file write table2b "\multicolumn{4}{p{42em}}{\textbf{Notes:} This table presents the pick up rates and listening rates for each section of financial heuristics training curriculum. Pick up rate = number of pickups / total number of calls. Listing rate regardless of pick up = listenership / total duration. Listening rate conditional on pick up = listenership / total duration if call picked up.} \\"
file write table2b "\bottomrule \\" _n
file write table2b "\end{tabular}% \\" _n
file write table2b "\label{tab:addlabel}% \\" _n
file write table2b "\end{adjustbox} \\" _n
file write table2b "\end{table}% \\" _n
file write table2b "\end{document}"


file close table2b
set more on
